﻿function checkall(fundId,fundName,isChecked,name, isFirstLoad)
{  
   var value=fundId+","+fundName;
       
   if(isChecked)
   {
      createlist(value,name, isFirstLoad);  
   }
   else
   {       
      var listobj=$(fundId);
      if(listobj != null)
      {
         listobj.parentNode.removeChild(listobj);    
      }
   }
}

function HideWindow()
{
    showOpenWindowFlag = false;
    var iframe = document.getElementsByTagName("iframe")[0];     
	iframe.contentWindow.openwindowFlag = false;  
    ojbWindow = $("comparewindow");
    ojbWindow.style.display = "none";    
}

var showOpenWindowFlag = false;
function openwindow(name)
{
   ojbWindow = $("comparewindow");
   if(ojbWindow != null)
   {
       ojbWindow.parentNode.removeChild(ojbWindow); 
   }
   
   showOpenWindowFlag = true;
   
   var div=$C("ul");
   document.body.appendChild(div);
   div.className="openwindow";
   div.id="comparewindow";
   div.style.display = "none";   
   div.innerHTML='<div style="color:#ff0000;font-size:14px;" id="showall"><img border="0" style="margin-right:5px;cursor:pointer;float:right;"  align="absmiddle" onclick="HideWindow();" title="关闭" src="/image/close_button.gif" /><span id="productTitle">您已经选择的基金</span></div><div class="hide" id="showproduct"><ol  id="list"></ol></div><span style="text-align:center;display:block;"><a href="javascript:void(0)" onclick="SaveFunds(this,\''+name+'\')"><img src="/image/SaveButton.gif" width="53" height="22"></a><span></div>';

   setInterval("autowidth()",100);
   
   if(typeof(User) != 'undefined' && typeof(User.FavoriteFund) != 'undefined')
   {
       var codes = User.FavoriteFund.split(';');
       var name = "";
       
       for(var i=0;i<codes.length;i++)
       {
           if(codes[i] != "")
           {
               name = eval("fund"+codes[i]);
               if(name == 'undefined')
               {
                    name = codes[i];
               }
               checkall(codes[i], name, true, "Fav_fund", true);
           }
       } 
   }
}

function delchoose(obj,name,values)
{
    var parent=obj.parentNode;
    var id=parent.id;
    var value=id+","+values;
    parent.parentNode.removeChild(parent);
    
    var iframe = document.getElementsByTagName("iframe")[0];     
	iframe.contentWindow.delchooseMyFavoriteFund(id);
}

function createlist(list, name, isFirstLoad)
{    
    var strs=list.split(",");
    var li=$C("li");
    var color = "";
    if(typeof isFirstLoad != 'undefined' && isFirstLoad == true)
    {        
        $("list").appendChild(li);
    }
    else
    {
        li.style.color = "#FF6600";
        $("list").insertBefore(li, $("list").firstChild);
    }
    
    li.id=strs[0];    
    li.innerHTML="<img border='0' style='margin-right:5px;width:10px;height:10px;cursor:pointer;' onclick='delchoose(this,\""+name+"\",\""+strs[1]+"\")' title='删除此行' src='/image/close.jpg' />&nbsp;"+strs[1];
}

function createAllist(allcookies,name)
{ 
  var strs=allcookies.split("|");
  for(var i=0;i<strs.length;i++)
  {
      createlist(strs[i],name);
  }
}

function autowidth()
{
   var div=$("comparewindow");

   myoffset = 0;

   if(this.IsIE)
   {
      //myoffset = 15;
   }
   
   div.style.top=(parseInt(document.documentElement.scrollTop,10)+(document.documentElement.clientHeight - div.offsetHeight) - myoffset) + 'px';
   div.style.left=parseInt((document.documentElement.clientWidth - div.offsetWidth - 10), 10) + 'px';
  
   if($("comparewindow").style.display != "block")
   {
      if(showOpenWindowFlag == true)
      {
        $("comparewindow").style.display = "block";  
      }
   }
   if($("showproduct").className != "show")
   {       
       $("showproduct").className="show";
   }
}

function SaveFunds(obj,tag)
{
    var showproduct=$("productTitle");
    showproduct.innerHTML="正在保存中....";
    
    var codes = [];
    objs = $("list").childNodes;
    for(var i=0;i<objs.length;i++)
    {
        codes.push(objs[i].id);
    }
    favCodes = codes.join(";");
    var time = new Date();
    var url = "/GetData.aspx?t=SetMyFunds&UserName="+escape(User.Name)+"&Codes="+escape(favCodes)+"&time="+time.getTime();
    AjaxRequest.CallbackByGet(url, callbackFavorite); 
}

function callbackFavorite()
{
    var showproduct=$("productTitle");
    showproduct.innerHTML="保存成功！";
    HideWindow();
}